package main.inquiry;

import base.BaseCanvasWindow;

import dao.ExcellentStudentCanvasDao;
import model.ExcellentStudent;

import java.awt.*;
import java.sql.*;
import java.util.List;

public class ExcellentStudentCanvas extends BaseCanvasWindow {

    @Override
    protected String setCanvasTitle() {
        return "优秀学生名单";
    }

    @Override
    protected Canvas setCanvasContent() {
        return new ExcellentStudentArea();
    }

    class ExcellentStudentArea extends Canvas {
        public void paint(Graphics g) {
            g.setColor(Color.BLACK);
            g.drawString("以下优秀学生名单", 80, 20);
            g.drawString("学号", 70, 40);
            g.drawString("姓名", 160, 40);

            try {
                List<ExcellentStudent> list = ExcellentStudentCanvasDao.getExcellentStudents();
                int length = list.size();

                for(int i=0;i<length;i++) {
                    ExcellentStudent excellentStudent = list.get(i);
                    String sno = excellentStudent.getSno();
                    String sname = excellentStudent.getSname();

                    g.drawString(sno, 70, 60 + 20 * i);
                    g.drawString(sname, 160, 60 + 20 * i);
                }

            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}
